<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.talkweb.ncfw.security.SecurityHelper,com.talkweb.ncfw.data.IUserSession" %>
<%@ include file="/foundation/ext/jsp/workspace.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<style type="text/css">
		    #rightToolNav {
		    	float:right;width:260px;z-index:999;position:relative;
		    	margin:18px 0px 0px 0px;
		    }
		    #rightToolNav li {
		    	float:right;padding-left:20px; margin:0 10 2 0px;
		    }
		    #rightToolNav li a {
		    }
		    .menuItem {
		    	text-align:center; width: 160px;
		    }
		    .menuItem_over {
		    	text-align:center; width: 160px; background: url('<%=basePath%>foundation/images/u151_hover.png') x-repeat scroll 0px 0px;
		    }
		    .menuItem a {
			    font-family:微软雅黑;font-size:20px;font-weight:bold;font-style:normal;text-decoration:none;color:#FFFFFF;
			}
		    .menuContainer a:hover  {
			    font-family:微软雅黑;font-size:20px;font-weight:bold;font-style:normal;text-decoration:none;color:#FFFFFF;
			}
		</style>
		<script type="text/javascript">
		
		
			function mover (src) {
				src.style.backgroundImage = "url('<%=basePath%>foundation/images/u151_hover.png')";
			}
			function mout (src) {
				src.style.backgroundImage = "";
			}
		</script>
	</head>
	<body>
		<div id="header">
			 <table border='0' height="100%" cellspacing='0' cellpadding='0' style="width:100%; float:left;position:absolute;">
			 	<tr height="70%">
			 		<td style="background: url('<%=basePath%>foundation/images/u0_original.jpg') no-repeat scroll 0px 0px;"></td>
			 	</tr>
			 	<tr height="30%" >
			 		<td align="left" style="background-image: url('<%=basePath%>foundation/images/u14_original.png')" id="menuNav">
						<span class="menuContainer"><span class="menuItem" onclick="javascript: alert('ok')">物理设备管理</span></span>
						<INPUT type="image" id=u20 src="<%=basePath%>foundation/images/transparent.gif" class="u20">
						
						<span class="menuContainer"><span class="menuItem" onmouseover="mover(this)" onmouseout="mout(this)"><a href="javascript: alert('ok')" >物理设备管理</a></span></span>
						<INPUT type="image" id=u20 src="<%=basePath%>foundation/images/transparent.gif" class="u20">
						
						<span class="menuContainer"><span class="menuItem" >物理设备管理</span></span>
						<INPUT type="image" id=u20 src="<%=basePath%>foundation/images/transparent.gif" class="u20">
						
						<span class="menuContainer"><span class="menuItem" >物理设备管理</span></span>
						<INPUT type="image" id=u20 src="<%=basePath%>foundation/images/transparent.gif" class="u20">
						
						<span class="menuContainer"><span class="menuItem" >物理设备管理</span></span>
						<INPUT type="image" id=u20 src="<%=basePath%>foundation/images/transparent.gif" class="u20">
			 		</td>
			 	</tr>
			 </table>
			 <div id="title" style="float: left; position: absolute; font-size: 22px; margin-bottom: 30px; display: none;"><h1 style="color: #ffffff">基础框架平台</h1></div>
			 <div id="rightToolNav">
				 <ul>
				 	<li class="exitlink"><a href="javascript:logout()">退出系统</a></li>
				 </ul>
			 </div>
		</div>
	</body>
	<script type="text/javascript">
		<%
			IUserSession userSession = SecurityHelper.getCurrentUser();
			boolean loginFlag 		= userSession != null;
			String username			= userSession.getUsername();
			if (username == null || username.length() == 0) {
				username = userSession.getUsername();
			}
		%>
		
		function initMenuNav () {
			Ext.Ajax.request({
				url : sys.basePath + "systemmenu/findMenu.do",
			   	method : 'post',
			   	success: function (response, options) {
					var menuArray = Ext.util.JSON.decode(response.responseText);
			   		if (menuArray == null || menuArray.length == 0) {
			   			return;
				   	}
				   	var menuItemHTML = "";
				   	for (var i = 0; i < menuArray.length; i++) {
				   		menuItemHTML += '<span class="menuContainer"><span class="menuItem" onclick="javascript: menuItemClick(\'' + menuArray[i].menuId + '\')">' 
				   			+ menuArray[i].menuLabelName + '</span></span>'
				   			+ '<input type="hidden" id="menuEntry_' + menuArray[i].menuId + '" value="' + menuArray[i].menuEntry + '"/>';
				   	}
				   	//alert(menuItemHTML);
				   	document.getElementById("menuNav").innerHTML = menuItemHTML;
			   	},
			   	failure: function () {
					Ext.MessageBox.hide();
				   	Ext.Msg.show({
		                title: '失败提示',
		                msg: '初始化导航菜单时发生异常.',
		                width: 180,
		                modal: false,
		                buttons : Ext.Msg.OK,
		                icon: Ext.MessageBox.ERROR
		            });
			   	}
			});
		}
		
		function menuItemClick (menuId) {
			var action = document.getElementById("menuEntry_" +　menuId).value;
			if(!Ext.isEmpty(action) && action != "null"){
    			var prefix = '?';
    			if (action.split('?') > 1) {
    				prefix = '&'
        		}
           		Ext.getDom("x-workspace").src = sys.basePath + action + prefix + 'random=' + Math.random();
           	}
		}
	
		var loginFlag = <%=loginFlag%>;
		if(!loginFlag){
			window.location.href = "<%=basePath%>login.jsp";
		}
           
		Ext.onReady(function() {
		
			//Ext.getDom('header').style.visibility = 'visible';
			//Ext.getDom('header').style.display = 'none';
			//initMenuNav();
			
			var centerArray = Ext.get('title').getCenterXY();
			var centerX = centerArray[0];
			var centerY = centerArray[1];
			
			Ext.getDom('title').style.margin = "8 0 5 " + centerX + "px";
			
			// layout start
			var viewport = new Ext.Viewport({
				layout: 'border',
				items: [{
					region: 'north',
					margins : '2 3 0 2',
					contentEl: 'header',
					height: 112,
					split : false
				}, {
		        	region:'center',
		        	border: false,
					margins : '1 2 3 0',
					html: "<iframe src='<%=basePath%>ncfw/user/user.jsp' name='x-workspace' id='x-workspace' width='100%' height='100%' frameborder='0'></iframe>"
				}]
			});
		});
		
		// Ext.util.CSS.swapStyleSheet("theme", "<%=basePath%>foundation/ext/resources/css/xtheme-calista.css");
		
		function logout() {
			Ext.Msg.confirm('操作提示', '您确定要退出本系统?', function(btn) {
				window.location.href = '<%=basePath%>logout';
			});
		}

		var task = {
			run: checkSessionExpire,
		   	interval: 15000		//15秒
		};
		var taskRunner = new Ext.util.TaskRunner();
		function checkSessionExpire(){
			Ext.Ajax.request({
				url: '<%=basePath%>checkSessionExpire.do',
				timeout: 6000,
				method: 'post',
				success: function(response, options){
					var result = Ext.util.JSON.decode(response.responseText);
					if (Ext.isEmpty(result.success)) {
						taskRunner.stop(task);
					}
					if (result.success) {
						taskRunner.stop(task);
						Ext.Msg.show({
							title: '提示信息',
						   	msg: 'session失效, 请重新登录!',
						   	buttons: Ext.Msg.OK,
						   	fn: function () {
						   		window.location.href = "<%=basePath%>login.jsp";
						   	},
						   	icon: Ext.MessageBox.INFO
						});
					}
					
				},
				failure: function(){
					taskRunner.stop(task);
				} 
			});
		}
		//taskRunner.start(task);

	</script>
</html>

